package ltd.followkba.comment;

/**
 * Created by WangZuSong@gmail.com on 2016/12/27.
 */

//public class MREG {
//    public static byte gAutoReadCommTimer;
//    public static byte gAutoReadCommSet;
//    public static boolean FSinaWeiboTx;
//    public static byte gSinaWeiboRx;
//    public static String gsChangBaSsid;
//    private static RegisteChangBa mRegisterChangBa;
//    private static int g4RegisterChangBa;
//
////    public static void CreateHaveSongDbsUser(){
////        gAutoReadCommTimer = 19;
////        gAutoReadCommSet = 19;
////        gsChangBaSsid = MRAM.gsFilePath + "ChangBaSsid.txt";
////        mRegisterChangBa = new RegisteChangBa();
////
////        gSinaWeiboRx = 0;
////        if (!"".equals(MAPI.RD_PRIVATE_STRING("weiboRx", MBAPP.gsMainMem))) {
////            gSinaWeiboRx = 1;
////            g4RegisterChangBa = 1;
////        }
////        else {
////            g4RegisterChangBa = 300;
////        }
////
////        FSinaWeiboTx = false;
////        if (!"".equals(MAPI.RD_PRIVATE_STRING("weiboTx", MBAPP.gsMainMem))) {
////            FSinaWeiboTx = true;
////        }
////
////        Runnable runnable = new Runnable() {
////            public void run() {
////                KgHaoChang HaoChangUserDbs = new KgHaoChang();
////                while (MKCS.mLockHaveSong[cKCB_SW_HAOCHANG] == null){
////                    MAPI.MSLEEP(1000);
////                }
////                while (!MKCS.isSystemClose) {
////                    MAPI.MSLEEP(1000);
////                    try {
////                        MKCS.mLockHaveSong[cKCB_SW_HAOCHANG].acquire();
////                        HaoChangUserDbs.CreateHaveSongDbsUser();
////                        MKCS.mLockHaveSong[cKCB_SW_HAOCHANG].release();
////                    } catch (InterruptedException e) {
////                        e.printStackTrace();
////                    }
////                }
////            }
////        };
////        Thread thread = new Thread(runnable);
//////        thread.start();
////    }
//
//    public static void OnTimer(){
//        if (MKCS.isAssignTask) {
//            AssignAllTask();
//        }
////        if (gAutoReadCommTimer > 0 && ++gAutoReadCommTimer > gAutoReadCommSet){
////            gAutoReadCommTimer = 0;
////            AutoReadCommentTask();
////        }
//////
//        if (gSinaWeiboRx == 1 && !FSinaWeiboTx) {
//            gSinaWeiboRx = 2;
////            mRegisterChangBa.RegisterAccount();
//        }
////        if (!FSinaWeiboTx && gSinaWeiboRx == 0) {
//////g4RegisterChangBa=900;
//////            MAPI.SYS_DEC(g4RegisterChangBa);
////            if (g4RegisterChangBa > 0 && ++g4RegisterChangBa > 300){
//////				g4RegisterChangBa = 0;
////                g4RegisterChangBa = 1;
////                byte[] gLocal_RxBuffer = new byte[2 + 1460];
////                String gsLocal_1 = "2Weibo";
////                String gsLocal_2 = TOOLS_Command(cKCB_TOOL_UP_REGISTER, 0, gsLocal_1.getBytes().length, gsLocal_1.getBytes(), gLocal_RxBuffer);
////                if ("ok".equals(gsLocal_2)) {
////                    int g4Local_1 = MAPI.BUFF8_WORD(0, gLocal_RxBuffer);
////                    if (g4Local_1 > 6) {
////                        GetWeiboFromSvr(g4Local_1, gLocal_RxBuffer);
////                    }
////                }
////            }
////        }
////        if (FSinaWeiboTx){
////            String gsLocal_1 = MAPI.RD_PRIVATE_STRING("weiboTx", MBAPP.gsMainMem);
////            byte[] gLocal_RxBuffer = new byte[2 + 1460];
//// MAPI.MSTRING(0xc1);MAPI.MSTRING(gsLocal_1);
////            String gsLocal_2 = TOOLS_Command(cKCB_TOOL_UP_REGISTER, 0, gsLocal_1.getBytes().length, gsLocal_1.getBytes(), gLocal_RxBuffer);
////            if ("ok".equals(gsLocal_2)) {
////MAPI.MSTRING(0xae);
////                FSinaWeiboTx = false;
////                MAPI.WR_PRIVATE_STRING("weiboTx", "", MBAPP.gsMainMem);
////            }
////        }
//
//    }
//    private static void AssignAllTask(){
//
////        MSTRING("AssignAllTask A "+MKCS.mBTaskRuns.size()+" "+MKCS.gsTaskFile[1]);
////        MSTRING("AssignAllTask B "+sysUtils.readTextFile(MKCS.gsTaskFile[1]));
////        MSTRING("AssignAllTask C "+MAPI.RD_PRIVATE_STRING(0, MKCS.gsTaskFile[1]));
//        Runnable runnable = new Runnable() {
//            public void run() {
//                int g4Local_1;
//                int g4Local_2;
//                if (MKCS.mBTaskRuns != null && MKCS.mBTaskRuns.size() > 0) {
//                    g4Local_1 = MKCS.mBTaskRuns.size();
//                    g4Local_2 = 0;
//                    MKCS.ShowToAllScreen(String.format("当前运行的任务%d个，等待结束", g4Local_1));
//                    while (g4Local_2 < g4Local_1) {
//                        if (MKCS.mBTaskRuns != null){
//                            MKCS.gsWorkStatus[MKCS.mBTaskRuns.get(g4Local_2).AppType] = "正在结束当前任务";
//                            if (MKCS.mBTaskRuns.get(g4Local_2).IsBusy) {
//                                MAPI.MSLEEP(1000);
//                            }
//                        }
//                        ++g4Local_2;
//                    }
//                    MKCS.ShowToAllScreen("结束当前运行的所有任务，重新分配任务");
//                }
//                byte appType = 0;
//                MKCS.mBTaskRuns = new ArrayList<>();
////MSTRING("AssignAllTask 1 "+MKCS.g4SetMaxTask);
//                do {
////                    g4Local_1 = MKCS.g4SetMaxTask;
//                    List<BAccount> lists = MBAPP.getTaskAccountList(appType);
//                    int length = lists.size();
//                    BAccount bAccount;
//                    for (int counter = 0; counter < length; counter++) {
//                        bAccount = lists.get(counter);
////                        if (appType==cKCB_SW_CHANGBA&&counter < 5) {
////                            MSTRING("AssignAllTask AA " + counter+" "+ bAccount);
////                        }
//                        if (bAccount != null){
//                            if (appType==cKCB_SW_CHANGBA&&counter < 5) {
//                                MSTRING("AssignAllTask BB " + bAccount.TaskID +" "+ bAccount.AccountName + " " + bAccount.Password);
//                            }
//                            MKCS.gsWorkStatus[appType] = "正在分配任务 "+ bAccount.TaskID;
//                            BTaskRun bOwnerRun = new BTaskRun();
//                            bOwnerRun.Index = bAccount.TaskID;
//                            bOwnerRun.AppType = appType;
//                            bOwnerRun.OwnApp = MKCS.SwitchBaseApp(appType);
//                            bOwnerRun.mBAccount = lists.get(counter);
//                            bOwnerRun.mOwnDetail = MBAPP.getUserDetail(appType, bOwnerRun.mBAccount.UserID);
//                            bOwnerRun.OwnApp.downloadHeadFile(bOwnerRun.mOwnDetail);
//                            MSTRING(String.format("AssignAllTask CC %s %s %d %s", bOwnerRun.mBAccount.AccountStatus, bOwnerRun.mOwnDetail.UserName, MAPI.GET_FILE_LENGTH(bOwnerRun.mOwnDetail.HeadFile), bOwnerRun.mOwnDetail.HeadFile));
//                            MKCS.mBTaskRuns.add(bOwnerRun);
//                        }
//                    }
////                    g4Local_2 = 0;
////                    while (g4Local_2 < g4Local_1) {
////                        String gsLocal_1 = MAPI.RD_PRIVATE_STRING(g4Local_2, MKCS.gsTaskFile[appType]);
////if (appType==cKCB_SW_CHANGBA&&g4Local_2 < 5) {
//////MSTRING("AssignAllTask E " + g4Local_2 + " "+gsLocal_1);
////}
////                        if (!"".equals(gsLocal_1)) {
////                            MKCS.gsWorkStatus[appType] = "正在分配任务 "+g4Local_2;
////                            BTaskRun bMainTask = new BTaskRun();
////                            bMainTask.Index = g4Local_2;
////                            bMainTask.AppType = appType;
////                            bMainTask.OwnApp = MKCS.SwitchBaseApp(bMainTask.AppType);
////                            bMainTask.AccountStatus = "未登录";
////                            bMainTask.LoginAccount = gsLocal_1;
////                            MKCS.mBTaskRuns.add(bMainTask);
////                        }
////                        ++g4Local_2;
////                    }
//                } while (++appType < cKCB_SW_MAXIMAL);
//                MKCS.isAssignTask = false;
//                MKCS.gTaskUpdate = 0x7f;
//                MKCS.ShowToAllScreen(String.format("准备运行的任务%d个", MKCS.mBTaskRuns.size()));
//            }
//        };
//        Thread thread = new Thread(runnable);
//        thread.start();
//    }
//    private static void AutoReadCommentTask(){
//        if (g4RegisterChangBa > 0 && ++g4RegisterChangBa > 30) {
//            g4RegisterChangBa = 0;
//            Runnable runnable = new Runnable() {
//                public void run() {
////                    int g4Local_1;
////                    byte[] gLocal_RxBuffer = new byte[2 + 1460];
////                    String gsLocal_1 = "2Weibo";
////                    gsLocal_1 = TOOLS_Command(cKCB_TOOL_UP_REGISTER, 0, gsLocal_1.getBytes().length, gsLocal_1.getBytes(), gLocal_RxBuffer);
//////MSTRING("gsLocal_1 "+gsLocal_1 +" "+gLocal_RxBuffer[0]);
////                    if ("ok".equals(gsLocal_1)) {
////                        g4Local_1 = MAPI.BUFF8_WORD(0, gLocal_RxBuffer);
////                        MSTRING("g  4Local_1 "+g4Local_1);
////                        if (g4Local_1 > 6) {
////                            GetWeiboFromSvr(g4Local_1, gLocal_RxBuffer);
////                        }
////                    }
////                    g4RegisterChangBa = 1;
//                }
//            };
//            Thread thread = new Thread(runnable);
//            thread.start();
//        }
//    }
//    private static void GetWeiboFromSvr(int length, byte[] rx_data){
//        String gsLocal_2 = new String(rx_data, 2 + 6, length - 6);
//        String[] params = gsLocal_2.split("\\$");
//MSTRING(String.format("从服务器读到%d微博号：%s", length, gsLocal_2));
//        if (params.length > 1) {
////MAPI.MSTRING(gsLocal_2);
//            int g4Local_1 = 1;
//            while (g4Local_1 < params.length) {
//                gsLocal_2 = params[g4Local_1++] + "\r\n";
////MAPI.MSTRING(0xa7);MAPI.MSTRING(gsLocal_2);
//                MAPI.WRITE_BUFF8_FILE(true, gsLocal_2.getBytes().length, 0, gsLocal_2.getBytes(), gsChangBaSsid);
//            }
//        }
//        gSinaWeiboRx = 1;
//        MAPI.WR_PRIVATE_STRING("weiboRx", params[0], MBAPP.gsMainMem);
//    }
//    public static void TaskReadMemoryFromFile(BTaskRun bOwnerRun){
////        bOwnerRun.StepCounter = bOwnerRun.StepTime;
////        CFileDbs commentQtyDbs = new CFileDbs(bOwnerRun.OwnApp.gsCommentQtyDbs);
////        int g4Local_1  = commentQtyDbs.GetUserID4Byte(bOwnerRun.OwnApp.gsUserID);
////        if (g4Local_1 > 0) {
////            bOwnerRun.SuccessQty = g4Local_1;
////        }
////        commentQtyDbs.close();
////
////        CFileDbs flowerRecoderDbs = new CFileDbs(bOwnerRun.OwnApp.gsFlowerQtyFile);
////        g4Local_1 = flowerRecoderDbs.GetUserID4Byte(bOwnerRun.OwnApp.gsUserID);
////        if (g4Local_1 > 0) {
////            bOwnerRun.FlowerQty = g4Local_1;
////        }
////        flowerRecoderDbs.close();
//        //       WriteToLogFile("TaskReadMemoryFromFile " + bOwnerRun.SuccessQty + " " + bOwnerRun.FlowerQty);
//    }
////    public static boolean UploadAppLoginToken(int index, BTaskRun bOwnerRun, String account, String password){
////         byte[] gpLocal_1 = bOwnerRun.OwnApp.MixAccountToBuffer(bOwnerRun.OwnApp.LoginFlag, "");
////        if (gpLocal_1 == null) {
////            return false;
////        }
////        byte[] gpLocal_2 = new byte[1460];
////        gpLocal_2[0] = (byte)(bOwnerRun.OwnApp.AppType + 'A');
////        byte[] gLocal_RxBuffer = new byte[2+1460];
////        MAPI.COPY_BUFF8(gpLocal_1.length, 0, gpLocal_1, 1, gpLocal_2);
////        String gsLocal_1 = MREG.TOOLS_Command(cKCB_TOOL_WR_KGAPP_DBS, 0, 1+gpLocal_1.length, gpLocal_2, gLocal_RxBuffer);
//////gsLocal_1="ok"; // 0409
////        MSTRING(String.format("UploadAppLoginToken A %d %d %s %s %s", index, bOwnerRun.AppType, account, password, gsLocal_1));
////        if ("ok".equals(gsLocal_1)){
////            gsLocal_1 = CodeBase64.encodeBytes(gpLocal_1);
//////            bOwnerRun.LoginAccount = String.format("%s----%s----0%s", account, password, gsLocal_1);
////            MSTRING(String.format("成功上传帐号信息到服务器 B %d %s %s", gpLocal_1.length, gsLocal_1, bOwnerRun.OwnApp.LoginFlag));
////            BAccount bAccount = new BAccount();
////            bAccount.AccountName = account;
////            bAccount.Password = password;
////            bAccount.MixToken = gsLocal_1;
////            MBAPP.setTaskAccount(bOwnerRun.AppType, bAccount);
//////            MAPI.WR_PRIVATE_STRING(index, bOwnerRun.LoginAccount, MKCS.gsTaskFile[bOwnerRun.AppType]);
//////MSTRING("jj " + bOwnerRun.OwnApp.Base64MixAccount(gsLocal_1));
////            return true;
////        }
////        MTOAST("上传帐号信息到服务器出错：" + gsLocal_1);
////        return false;
////    }
//
//    public static String TOOLS_Command(int type, int subType, int length, byte[]in_data, byte[]out_data){
//        return cjmkcs.systemWriteKcbCommand(0, (cKCB_TYPE_TOOLS<<16)|(type<<8)|subType, length, in_data, out_data, 0);
//    }
//
//}
